<?php

namespace App\Http\Resources\System\Admin;

use App\Http\Resources\BaseResource;
use Illuminate\Http\Request;

class IndexResource extends BaseResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'userId' => $this->id,
            'username' => $this->username,
            'nickname' => $this->nickname,
            'roles' => $this->roles->pluck('code'),
            'avatar' => $this->avatar ? $request->getSchemeAndHttpHost().$this->avatar : '',
            'mobile' => $this->mobile ? preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $this->mobile) : '',
            'email' => $this->email ?: '',
            'desc' => '描述',
            'homePath' => '/workspace',
            'token' => '123',
            'realName' => $this->nickname,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
